<template>
  <div class="sign">
    <!-- 星期 -->
    <div class="sign-week">
      <div
        class="sign-week-item"
        v-for="(item, index) in weeks"
        :key="index + 'k'"
      >
        星期{{ item.value }}
      </div>
    </div>
    <!-- 日期 -->
    <div class="sign-data">
      <div
        class="sign-data-item"
        v-for="(item, index) in datas"
        :key="index + 'i'"
        @click="signIn(item)"
      >
        {{ item.value }}
        <svg-icon
          v-if="item.isSign"
          class="sign-data-item-signlogo"
          iconFileName="sign-in"
        ></svg-icon>
      </div>
    </div>
  </div>
</template>
<script>
import { weekData, signInList, getDaysInCurrentMonth } from "./index";
export default {
  data() {
    return {
      weeks: weekData,
      datas: getDaysInCurrentMonth(null, signInList),
    };
  },
  created() {},
  methods: {
    // 今日签到
    signIn(item) {
      // 当已签到时跳过后续操作
      if (item.isSign) {
        return;
      }
      // 当点击不是当天时跳过后续操作
      if (item.value !== new Date().getDate()) {
        return;
      }
      this.$nextTick(() => {
        item.isSign = true;
      });
    },
  },
};
</script>

<style lang="scss" scoped>
// 这里可以编写 SCSS 样式
.sign {
  width: 100%;
  // 禁止文本被选中
  user-select: none;
  box-sizing: border-box;
  padding: 10px 20px;
  &-week {
    width: 706px;
    display: grid;
    grid-template-columns: repeat(7, 100px);
    grid-template-rows: 60px;
    &-item {
      width: 100px;
      height: 60px;
      border-top: 1px solid #e5e5e5;
      border-left: 1px solid #e5e5e5;
      border-bottom: 1px solid #e5e5e5;
      text-align: center;
      line-height: 60px;
      box-sizing: border-box;
      &:last-child {
        border-right: 1px solid #e5e5e5;
      }
      &:hover {
        cursor: pointer;
      }
    }
  }

  &-data {
    width: 706px;
    display: grid;
    grid-template-columns: repeat(7, 100px);
    grid-template-rows: repeat(5, 60px);
    &-item {
      width: 100px;
      height: 60px;
      border-left: 1px solid #e5e5e5;
      border-bottom: 1px solid #e5e5e5;
      text-align: center;
      line-height: 60px;
      box-sizing: border-box;
      position: relative;
      &:nth-child(7n) {
        border-right: 1px solid #e5e5e5;
      }
      &:last-child {
        border-right: 1px solid #e5e5e5;
        box-sizing: content-box;
        width: 99px;
        height: 59px;
      }
      &:hover {
        cursor: pointer;
        background-color: #e5e5e5;
      }
      &-signlogo {
        position: absolute;
        top: 5px;
        right: 5px;
        width: 30px;
        height: 30px;
      }
    }
  }
}
</style>
